/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [http://neo4j.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.gds.settings;

import org.neo4j.configuration.BootloaderSettings;
import org.neo4j.configuration.GraphDatabaseSettings;
import org.neo4j.configuration.SettingValueParsers;
import org.neo4j.configuration.connectors.BoltConnector;
import org.neo4j.configuration.connectors.HttpConnector;
import org.neo4j.configuration.connectors.HttpsConnector;
import org.neo4j.configuration.helpers.SocketAddress;
import org.neo4j.gds.compat.SettingsUtil;
import org.neo4j.graphdb.config.Setting;

import java.nio.file.Path;
import java.time.ZoneId;
import java.util.List;

public final class Neo4jSettings {

    public static Setting<Boolean> authEnabled() {
        return GraphDatabaseSettings.auth_enabled;
    }

    public static String defaultDatabaseName() {
        return GraphDatabaseSettings.DEFAULT_DATABASE_NAME;
    }

    public static String systemDatabaseName() {
        return GraphDatabaseSettings.SYSTEM_DATABASE_NAME;
    }

    public static Setting<Boolean> boltEnabled() {
        return BoltConnector.enabled;
    }

    public static Setting<SocketAddress> boltListenAddress() {
        return BoltConnector.listen_address;
    }

    public static Setting<Boolean> httpEnabled() {
        return HttpConnector.enabled;
    }

    public static Setting<Boolean> httpsEnabled() {
        return HttpsConnector.enabled;
    }

    public static Setting<ZoneId> dbTemporalTimezone() {
        return GraphDatabaseSettings.db_temporal_timezone;
    }

    public static Setting<Path> neo4jHome() {
        return GraphDatabaseSettings.neo4j_home;
    }

    public static Setting<Long> pageCacheMemory() {
        return GraphDatabaseSettings.pagecache_memory;
    }

    public static Long pageCacheMemoryValue(String value) {
        return SettingValueParsers.BYTES.parse(value);
    }

    public static <T> T disableOnlineBackup(T builder, SettingsUtil.SetConfig<T, Boolean> setConfig) {
        return SettingsUtil.tryConfigure(
            builder,
            setConfig,
            "com.neo4j.configuration.OnlineBackupSettings",
            "online_backup_enabled",
            Boolean.FALSE
        );
    }

    public static <T> T disableReplication(T builder, SettingsUtil.SetConfig<T, Boolean> setConfig) {
        builder = SettingsUtil.tryConfigure(
            builder,
            setConfig,
            "com.neo4j.configuration.EnterpriseEditionInternalSettings",
            "enable_replication",
            Boolean.FALSE
        );
        builder = SettingsUtil.tryConfigure(
            builder,
            setConfig,
            "com.neo4j.configuration.EnterpriseEditionInternalSettings",
            "replication_enabled",
            Boolean.FALSE
        );
        return builder;
    }

    public static Setting<List<String>> procedureUnrestricted() {
        return GraphDatabaseSettings.procedure_unrestricted;
    }

    public static Setting<Boolean> failOnMissingFiles() {
        return GraphDatabaseSettings.fail_on_missing_files;
    }

    public static Setting<String> additionalJvm() {
        return BootloaderSettings.additional_jvm;
    }

    private Neo4jSettings() {
        throw new UnsupportedOperationException();
    }
}
